<?php
class Pageley_Commerce_Command_RemoveItemsFromOrder extends Pageley_Controller_Command_TransactionalRead {

	private $indices;

	public function setIndices($indices) {
		$this->indices = $indices;
	}

	protected function executeInternal() {
		$order = $this->getSession()->get(Pageley_Commerce_Session::ORDER);
		if($order === null) {
            throw new Pageley_Controller_RuntimeException("Attempt to remove an order item when no order is present.");
        }
        if($this->indices !== null) {
	        foreach($this->indices as $index) {
	            $order->get("orderItems")->remove($index);
	        }
        }
	}
}